// To parse this JSON data, do
//
//     final messageModel = messageModelFromJson(jsonString);

import 'dart:convert';

MessageModel messageModelFromJson(String str) => MessageModel.fromJson(json.decode(str));

String messageModelToJson(MessageModel data) => json.encode(data.toJson());

class MessageModel {
  int id; // 消息id
  String messageContent; // 消息内容
  List<String> imageUrlList; // 图片url
  int userType; // 用户类型 0: 系统消息 1: 好友消息

  MessageModel({
    this.id = 0,
    this.messageContent = '',
    this.imageUrlList = const [],
    this.userType = 0,
  });

  factory MessageModel.fromJson(Map<String, dynamic> json) => MessageModel(
    id: json["id"],
    messageContent: json["messageContent"],
    imageUrlList: json["imageUrlList"] == null ? [] : List<String>.from(jsonDecode(json["imageUrlList"]).map((x) => x)),
    userType: json["userType"],
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "messageContent": messageContent,
    "imageUrlList": jsonEncode(imageUrlList),
    "userType": userType,
  };

  static List<MessageModel> listFromJson(List jsonList) {
    List<MessageModel> source = [];
    for (var element in jsonList) {
      source.add(MessageModel.fromJson(element));
    }
    return source;
  }
}
